<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<%@ include file="/common/mainhead.html" %>
<script type="text/javascript">	
	$(function(){
		$('#dg').datagrid({
			url:'resolveDataFromServerFileForTest.do?newFileName=${newFileName}',
		    	onLoadError:function(){
		    		top$.showWarnMessage("数据加载失败");
		    	},
		    	onLoadSuccess:function(data){
		    		if(data.flag == true){
		    			$('#hide_hasSameData').val('true');
		    		}else{
		    			$('#hide_hasSameData').val('false');
		    		}
		    	}
		});
	});
	
	function submitInfo(){
		var sameflag = $('#hide_hasSameData').val();
		if(sameflag == 'true'){
			top$.showWarnMessage("存在重复数据，请检查上传数据");
			return;
		}
		
		var rows = $('#dg').datagrid('getRows');
		var records = [];
		for(var i=0; i<rows.length; i++){
			var record = rows[i]['id']+parFlag+rows[i]['testValue']+parFlag+rows[i]['desc1']+parFlag+rows[i]['desc2']+parFlag+rows[i]['desc3']+parFlag+rows[i]['desc4'];
			records.push(record);
		}
		if(records.length>0){
			top$.messager.progress({
				title:'请等待...',
				msg:'数据保存中...'
			});
			$.ajax({
				type:'post',
				url:'saveTemplateDataForTest.do',
				data:{jsonstr:records.join(rdrecordFlag)},
				success:function(data){
					top$.messager.progress('close');					
					if (data.flag == JSON_FLAG_SUCCESS) {
						$('#butt_sub').linkbutton("disable");
						top$.messageBox5s(OPT_SUCCESS);
					} else {
						top$.messageBox5s(EDIT_FAIL + ':' + data.errmsg);
					}
				}
			});
		}else{
			top$.messageBox5s(ERROR_ITEMTEMP);
		}		
	}

</script>
</head>
<body>
	<div id="toolbar" style="padding:3px;height:25px;">
		<a href="#" id="butt_sub" class="easyui-linkbutton" onclick="submitInfo()" iconCls="icon-save" >保存</a>
		<span style="float:right;margin-right:30px;">
			<script>
			if (document.referrer) {
				document.write('<a href="'+document.referrer+'">返回</a>');
			}
			</script>
		</span>
	</div> 
	<div id="div_main">
		<table id="dg" data-options="singleSelect:true,width:'100%',height:'100%',rownumbers:true,loadMsg:'数据加载中，请稍后......',method:'get',toolbar:'#toolbar'">
			<thead>
				<tr>
					<th data-options="field:'id',width:40">序号</th>
					<th data-options="field:'testValue',width:80">值</th>
					<th data-options="field:'desc1',width:80">描述1</th>
					<th data-options="field:'desc2',width:80">描述2</th>
					<th data-options="field:'desc3',width:80">描述3</th>
					<th data-options="field:'desc4',width:80">描述4</th>
				</tr>
			</thead>
		</table>
	</div>
	<div>
		<input id="hide_newFileName" type="hidden" value="${newFileName}" /> 
		<input id="hide_hasSameData" type="hidden" />
	</div>
</body>
</html>